%update to path on your computer pointing to the VAR Toolbox
addpath(genpath('\\tsclient/C/Users/Jeff Levy/Documents/GitHub/VAR-Toolbox/v3dot0/VAR'))
addpath(genpath('\\tsclient/C/Users/Jeff Levy/Documents/GitHub/VAR-Toolbox/v3dot0/Utils'))
addpath(genpath('\\tsclient/C/Users/Jeff Levy/Documents/GitHub/VAR-Toolbox/v3dot0/Auxiliary'))
addpath(genpath('\\tsclient/C/Users/Jeff Levy/Documents/GitHub/VAR-Toolbox/v3dot0/Figure'))
addpath(genpath('\\tsclient/C/Users/Jeff Levy/Documents/GitHub/VAR-Toolbox/v3dot0/ExportFig'))
addpath(genpath('\\tsclient/C/Users/Jeff Levy/Documents/GitHub/VAR-Toolbox/v3dot0/Stats'))

california = readtable('california.csv')
california = california(~any(ismissing(california),2),:);
vnames = {'hf_ln_EPU_Composite', 'hf_unemp_rate'};
X = california{:,vnames};
X = X(:, [2 1]); %reverse ordering

% Set the deterministic variable in the VAR (1=constant, 2=trend)
det = 1;
nlags = 6;

[VAR, VARopt] = VARmodel(X,nlags,det);

%set VAR options
%VARopt.vnames = {'EPU-C', 'Unemployment Rate'};
VARopt.vnames = {'Unemployment Rate', 'EPU-C', }; %reverse ordering
VARopt.nsteps = 60;
VARopt.frequency = 'm';
VARopt.FigSize = [32,16];
VARopt.firstdate = 1987.9163;
VARopt.ident = 'short';

% irf
%VARopt.pick = 1;
VARopt.pick = 2; %reverse ordering
[IR, VAR] = VARir(VAR,VARopt);
[IRinf,IRsup,IRmed,IRbar] = VARirband(VAR,VARopt);
VARirplot(IRbar,VARopt,IRinf,IRsup);

% historical decomp
%VARopt.pick = 2;
VARopt.pick = 1; %reverse ordering
VARopt.quality = 0;
VARopt.vnames = {'Contribution of EPU Shocks', 'Contribution of Unemployment Rate Shocks'};
[HD, VAR] = VARhd(VAR,VARopt);
VARhdplot(HD,VARopt);